package org.example.pcbcircuitboard.controller;

import org.example.pcbcircuitboard.entity.SSEConnectEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;

/**
 * 创建SSE连接、数据推送到客户端 接口
 */
@RestController
@RequestMapping("/mqtt-sse")
public class MqttSSEController {
    /**
     * 获取页面 SSE 连接
     * @return SseEmitter连接对象
     */
    @GetMapping("/left-top-data")
    public SseEmitter leftTopData() {
        SseEmitter emitter = new SseEmitter(Long.MAX_VALUE);
        SSEConnectEntity.addEmitterConnection(SSEConnectEntity.leftTopUserId, emitter);
        return emitter;
    }
}
